home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / scripts / makeclean.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  1.1 KB  |  60 lines

  1. """      ***DANGEROUS***
  2.       script to remove 
  3.       all results of a 
  4.        build process. 
  5.  
  6.         ***Don't*** 
  7.     run this if you are
  8.          ***not***
  9.       building Python 
  10.       from the source
  11.             !!!
  12. """
  13.  
  14. import macfs
  15. import os
  16. import sys
  17. import re
  18.  
  19. sweepfiletypes = [
  20.     'APPL',     # applications
  21.     'Atmp',        # applet template
  22.     'shlb',     # shared libs
  23.     'MPSY',        # SYM and xSYM files
  24.     'PYC ',        # .pyc files
  25.     ]
  26.  
  27. sweepfolderre = re.compile(r"(.*) Data$")
  28.  
  29.  
  30. def remove(top):
  31.     if os.path.isdir(top):
  32.         for name in os.listdir(top):
  33.             path = os.path.join(top, name)
  34.             remove(path)
  35.     os.remove(top)
  36.  
  37.  
  38. def walk(top):
  39.     if os.path.isdir(top):
  40.         m = sweepfolderre.match(top)
  41.         if m and os.path.exists(m.group(1) + ".prj"):
  42.             print "removing folder:", top
  43.             remove(top)
  44.         else:
  45.             for name in os.listdir(top):
  46.                 path = os.path.join(top, name)
  47.                 walk(path)
  48.     else:
  49.         fss = macfs.FSSpec(top)
  50.         cr, tp = fss.GetCreatorType()
  51.         if tp in sweepfiletypes and top <> sys.executable:
  52.             print "removing file:  ", top
  53.             remove(top)
  54.         
  55.  
  56. fss, ok = macfs.GetDirectory("Please locate the Python home directory")
  57. if ok:
  58.     walk(fss.as_pathname())
  59.     sys.exit(1)  # so we see the results
  60.